using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Voodoo.Sauce.Internal.GDPR;

namespace Voodoo.Sauce.Internal.Analytics.Trackers
{
	public static class VoodooTrackers
	{
		private const string TAG = "VoodooTrackers";

		private static bool _consent;

		private const string os = "android";

		private static string _sessionId;

		public static void SetConsent(bool consent)
		{
			_consent = consent;
		}

		public static void TrackAppOpen()
		{
			_sessionId = Guid.NewGuid().ToString();
			TrackEvent("app_open");
		}

		public static void TrackFsShown()
		{
			TrackEvent("fs_shown");
		}

		public static void TrackRvShown()
		{
			TrackEvent("rv_shown");
		}

		public static void TrackCrossPromoEvent(string eventName, string promotedBundleId, string videoName)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			dictionary.Add("bundle_id_source_game", Application.identifier);
			dictionary.Add("bundle_id_promoted_game", promotedBundleId);
			dictionary.Add("video_name", videoName.Split('/').Last());
			dictionary.Add("platform", "android");
			dictionary.Add("session_id", _sessionId);
			dictionary.Add("voodoosauce_version", "3.4.0b4");
			Dictionary<string, string> parameters = dictionary;
			TrackersParams trackersParams = new TrackersParams();
			trackersParams.event_name = eventName;
			trackersParams.parameters = parameters;
			VoodooTrackersAPI.Track(trackersParams, null, null, crosspromo: true);
		}

		private static void TrackEvent(string eventName, Dictionary<string, string> parameters = null)
		{
			if (parameters == null)
			{
				parameters = new Dictionary<string, string>();
			}
			parameters.Add("bundle_id", Application.identifier);
			parameters.Add("voodoosauce_version", "3.4.0b4");
			parameters.Add("app_version", Application.version);
			parameters.Add("session_id", _sessionId);
			parameters.Add("platform", "android");
			parameters.Add("idfa", (!_consent) ? "no_consent_given" : VoodooGDPR.GetIDFA());
			parameters.Add("__localisation", "true");
			TrackersParams trackersParams = new TrackersParams();
			trackersParams.event_name = eventName;
			trackersParams.parameters = parameters;
			VoodooTrackersAPI.Track(trackersParams, null, null);
		}
	}
}
